# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from django.utils import timezone

# Create your models here.


class BxSlider(models.Model):
	"""轮播图数据模型"""
	status_choice = (
		(0, u'下线'),
		(1, u'上线')
	)
	status = models.IntegerField(verbose_name='状态', choices=status_choice, default=1)
	name = models.CharField(verbose_name='名称', max_length=25, db_index=True, unique=True)
	img = models.ImageField(verbose_name='上传', upload_to='./static/img/bxslider_img/')
	href = models.CharField(verbose_name='超链接', max_length=256)
	# create_date = models.DateTimeField(auto_now_add=True)  # auto_now...使用的是默认时区的日期，且默认设置editable=False和blank=True
	# update_date = models.DateTimeField(auto_now=True)
	create_date = models.DateTimeField(editable=False)
	update_date = models.DateTimeField(editable=False)

	# 重写save()(在save()函数里自己添加保存时间的机制)
	def save(self, *args, **kwargs):
		if not self.create_date:
			self.create_date = timezone.now()
		self.update_date = timezone.now()
		return super(BxSlider, self).save(*args, **kwargs)

	class Meta:
		db_table = 'sys_BxSlider'  # 该数据模型在数据库的表名
		verbose_name = u'首页轮播'  # 显示在admin后台中的
		verbose_name_plural = verbose_name  # 详细名称（单数）=详细名称（复数）
		ordering = ['create_date']  # 排序

	def __unicode__(self):
		return self.name


class Notice(models.Model):
	""""公告数据模型"""
	status_choice = (
		(0, u'不显示'),
		(1, u'显示'),
	)
	status = models.IntegerField(verbose_name='状态', choices=status_choice, default=0)
	weight = models.IntegerField(verbose_name='权重（大到小排）', default=0)
	title = models.CharField(verbose_name='标题', max_length=25)
	summary = models.CharField(verbose_name='简介', max_length=50)
	detail = models.CharField(verbose_name='详情', max_length=256, null=True, blank=True)  # null=True表示将空值存储为Null，blank=True表示该字段允许为空

	class Meta:
		db_table = 'sys_Notice'
		verbose_name = u'最新公告'
		verbose_name_plural = verbose_name

	def __unicode__(self):
		return self.title


class Recruit(models.Model):
	""""招聘数据模型"""
	status_choice = (
		(0, u'已过期'),
		(1, u'招聘中'),
	)
	status = models.IntegerField(verbose_name='状态', choices=status_choice, default=0)
	weight = models.IntegerField(verbose_name='权重', default=0)
	title = models.CharField(verbose_name='标题', max_length=20)
	salary = models.CharField(verbose_name='薪资', max_length=20)
	company = models.CharField(verbose_name='公司', max_length=20)
	detail = models.TextField(verbose_name='详情')
	deadline = models.DateField(verbose_name='截止日期')

	class Meta:
		db_table = 'sys_Recruit'
		verbose_name = u'招聘信息'
		verbose_name_plural = verbose_name

	def __unicode__(self):
		return self.title


class Student(models.Model):
	"""学员详情数据模型"""
	status_choice = (
		(0, u'下线'),
		(1, u'上线'),
	)
	status = models.IntegerField(verbose_name='状态', choices=status_choice, default=0)
	weight = models.IntegerField(verbose_name='权重（大到小排）', default=0)
	name = models.CharField(verbose_name='姓名', max_length=32, unique=True)
	pic = models.ImageField(verbose_name='头像', upload_to='./static/img/student_pic/', null=True, blank=True)
	company = models.CharField(verbose_name='公司', max_length=32)
	salary = models.CharField(verbose_name='薪资', max_length=10)

	class Meta:
		db_table = 'sys_Student'
		verbose_name = u'学员信息'
		verbose_name_plural = verbose_name

	def __unicode__(self):
		return self.name


class StudentDetail(models.Model):
	"""学员更多信息数据模型"""
	student = models.OneToOneField('Student')
	weight = models.IntegerField(verbose_name='权重（大到小排）', default=0)
	letter_of_thanks = models.TextField(verbose_name='学员感谢信', max_length=256)

	class Meta:
		db_table = 'sys_StudentDetail'
		verbose_name = u'学员更多信息'
		verbose_name_plural = verbose_name

	def __unicode__(self):
		return self.student.name


class Video(models.Model):
	"""视频数据模型"""
	status_choice = (
		(0, u'下线'),
		(1, u'上线'),
	)
	level_choice = (
		(1, u'初级'),
		(2, u'中级'),
		(3, u'高级'),
	)
	status = models.IntegerField(verbose_name='状态', choices=status_choice, default=0)
	level = models.IntegerField(verbose_name='等级', choices=level_choice, default=1)
	classfication = models.ForeignKey('Classification', null=True, blank=True)  # 外键与视频表连接起来，进行扩展
	weight = models.IntegerField(verbose_name='权重（大到小排）', default=0)
	title = models.CharField(verbose_name='标题', max_length=32)
	summary = models.CharField(verbose_name='简介', max_length=64)
	img = models.ImageField(verbose_name='图片', upload_to='./static/img/video_img/')
	href = models.CharField(verbose_name='视频地址', max_length=256)
	create_date = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

	class Meta:
		db_table = 'sys_Video'
		verbose_name = u'视频'
		verbose_name_plural = verbose_name

	def __unicode__(self):
		return self.title


class Classification(models.Model):
	"""视频分类数据模型"""
	weight = models.IntegerField(verbose_name='权重（大到小排）', default=0)
	name = models.CharField(verbose_name='名称', max_length=32)

	class Meta:
		db_table = 'sys_Chassification'
		verbose_name = u'视频分类'
		verbose_name_plural = verbose_name

	def __unicode__(self):
		return self.name


class Dirction(models.Model):
	"""视频方向数据模型"""
	weight = models.IntegerField(verbose_name='权重（大到小排）', default=0)
	name = models.CharField(verbose_name='名称', max_length=32)
	classification = models.ManyToManyField('Classification')

	class Meta:
		db_table = 'sys_Dirction'
		verbose_name = u'视频方向'
		verbose_name_plural = verbose_name

	def __unicode__(self):
		return self.name

